package cn.dc406.labc406mgr.controller;


import cn.dc406.labc406mgr.entity.Lenddetails;
import cn.dc406.labc406mgr.mapper.LenddetailsWapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class LenddetailsController {
    @Autowired(required = false)//注入相应对的内容
    LenddetailsWapper lenddetailsWapper;

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectALLlend")
    public List<Lenddetails> selectALLlend()
    {
        return lenddetailsWapper.selectALLlend();
    }


    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectApplication")
    public List<Lenddetails> selectApplication()
    {
        return lenddetailsWapper.selectApplication();
    }


    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectApplicationByUsername")
    public List<Lenddetails> selectApplicationByUsername(String username)
    {
        return lenddetailsWapper.selectApplicationByUsername(username);
    }
    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/Updatelend")
    public Boolean Updatelend(@RequestBody Lenddetails lenddetails)
    {
        System.out.println(lenddetails);
        return lenddetailsWapper.Updatelend(lenddetails);
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/accessApplication")
    public List<Lenddetails> accessApplication(Integer id)
    {
        if(lenddetailsWapper.accessApplication(id))
        {
            return lenddetailsWapper.selectApplication();
        }
        else return null;
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/accessAllApplication")
    public List<Lenddetails> accessAllApplication(@RequestBody List<Lenddetails> lenddetails)
    {
        System.out.println("accessAllApplication");
        for(Lenddetails lenddetail:lenddetails)
        {
            System.out.println(lenddetail);
            lenddetailsWapper.accessApplication(lenddetail.getId());
        }
        return lenddetailsWapper.selectApplication();
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/selectlendByUsername")
    public List<Lenddetails> selectlendByUsername(String username)
    {
        System.out.println(username);
        return lenddetailsWapper.selectlendByUsername(username);
    }

    @CrossOrigin()
    @ResponseBody
    @RequestMapping("/deletelendByID")
    public Boolean deletelendByUsername(Integer id)
    {
        System.out.println(id);
        return lenddetailsWapper.deletelendByID(id);
    }
}
